<template>
  <div class="common-page f-c">
    <BackPage title="绩效考核管理" />
    <div class="search-params f-r a-c j-b">
      <el-form inline>
        <el-form-item label="人员名称：">
          <el-input clearable v-model="searchParams.name" />
        </el-form-item>
        <el-form-item label="人员类型：">
          <el-select clearable v-model="searchParams.roleType">
            <el-option v-for="item in options" :key="item.value" :value="item.value" :label="item.name" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" round @click="onSearch">筛选</el-button>
          <el-button round @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
      <el-form>
        <el-form-item>
          <el-button type="primary" round @click="onAdd">考核规则配置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="table-box f-g">
      <el-table
        height="100%"
        v-loading="loading"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column type="index" width="80px" label="序号" align="center" />
        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="平均用户满意度" width="300px">
          <template slot-scope="scope">
            <el-rate
              :value="scope.row.score"
              disabled
              :max="5"
              show-score
              text-color="#ff9900"
              score-template="{value}"
            />
          </template>
        </el-table-column>
        <el-table-column label="总分" prop="completion" />
        <el-table-column label="操作" fixed="right" width="80px">
          <template slot-scope="scope">
            <el-button type="text" @click="onRead(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
    <ItemConfig ref="ItemConfigRef" />
    <ItemDetail ref="ItemDetailRef" />
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import ItemDetail from './detail'
import ItemConfig from './config'
import { http_performance } from '@/api'
export default {
  name: 'Index',
  components: {
    ItemDetail,
    ItemConfig
  },
  mixins: [crud],
  data() {
    return {
      request: http_performance,
      searchParams: {
        name: '',
        roleType: ''
      },
      options: [
        { value: 0, name: '代办人员' },
        { value: 1, name: '窗口人员' }
      ],
      columns: [
        { prop: 'realname', label: '人员名称' },
        { prop: 'roleTypeName', label: '人员类型' },
        { prop: 'projectNumber', label: '服务项目数' },
        { prop: 'scoreNumber', label: '用户满意度评价数' }
      ],
      tableData: []
    }
  },
  methods: {
    formatTableData(data) {
      data.forEach(el => {
        el.roleTypeName = this.options.find(item => item.value == el.roleType)?.name
      })
    },
    onAdd() {
      this.$refs.ItemConfigRef.open()
    },
    onRead(item) {
      this.$refs.ItemDetailRef.open(item)
    }
  }
}
</script>

<style scoped lang="scss">
</style>
